//package org.zjframework.traceframe.common.controller;
//
//import org.apache.log4j.Logger;
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.UUID;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.multipart.MultipartHttpServletRequest;
//import org.springframework.web.multipart.commons.CommonsMultipartResolver;
//import org.zjframework.traceframe.common.util.ContextHolderUtils;
//import org.zjframework.traceframe.common.util.FileUtils;
//
//@Controller
//public class InfoSetAction {
//	/**
//	 * Logger for this class
//	 */
//	private static final Logger logger = Logger.getLogger(InfoSetAction.class);
//
//	@Autowired
//	CommonsMultipartResolver multipartResolver;
//
//	@Autowired
////	IAttachmentService attachmentService;
//
//	@RequestMapping(value = "tempimg")
//	public void addCategory(HttpServletRequest request,
//							HttpServletResponse actioncontext,
//							String t) {
//		logger.info("添加图片");
//		String re  = null;
//		String sub = null;
//		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//		MultipartFile imgFile1 = multipartRequest.getFile("file");// 获取上次文件名
//		logger.info("----->" + imgFile1.getOriginalFilename());
//		List<String> fileTypes = new ArrayList<String>();
//		fileTypes.add("jpg");
//		fileTypes.add("jpeg");
//		fileTypes.add("bmp");
//		fileTypes.add("gif");
//		fileTypes.add("png");
//		if (!(imgFile1.getOriginalFilename() == null || "".equals(imgFile1
//				.getOriginalFilename()))) {
//			String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/image/");
//			logger.info("上传路径---->" + uploadfile);
//			File file1 = this.getFile(imgFile1, uploadfile, fileTypes);
//			logger.info("完成上传------>" + file1);
//			re=file1.toString();
//			sub=re.substring(re.lastIndexOf(System.getProperty("file.separator"))+1);			//linux下是/ windows下是 \\
//			logger.info("截取--->"+sub);
//		}
//		actioncontext.setContentType("text/html");
//		PrintWriter out;
//		try {
//			out = actioncontext.getWriter();
//			out.println("/attached/image/" + sub);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
//
////	@RequestMapping(value = "tempimg")
////	public void addCategory(HttpServletRequest request, String path1,
////							String path2, HttpServletResponse actioncontext) {
////		logger.info("添加图片");
////		String re  = null;
////		String sub = null;
////		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
////		MultipartFile imgFile1 = multipartRequest.getFile("file");// 获取上次文件名
////		logger.info("----->" + imgFile1.getOriginalFilename());
////		List<String> fileTypes = new ArrayList<String>();
////		fileTypes.add("jpg");
////		fileTypes.add("jpeg");
////		fileTypes.add("bmp");
////		fileTypes.add("gif");
////		fileTypes.add("png");
////		if (!(imgFile1.getOriginalFilename() == null || "".equals(imgFile1
////				.getOriginalFilename()))) {
////			String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/image/");
////			logger.info("--->" + path1 + "--->" + path2);
////			logger.info("上传路径---->" + uploadfile);
////			File file1 = this.getFile(imgFile1, uploadfile, fileTypes);
////			logger.info("完成上传------>" + file1);
////			re=file1.toString();
////			sub=re.substring(re.lastIndexOf(System.getProperty("file.separator"))+1);			//linux下是/ windows下是 \\
////			logger.info("截取--->"+sub);
////		}
////		actioncontext.setContentType("text/html");
////		PrintWriter out;
////		try {
////			out = actioncontext.getWriter();
////			out.println("/attached/image/" + sub);
////		} catch (IOException e) {
////			e.printStackTrace();
////		}
////	}
//
//
//    @RequestMapping(value="multiupload")
//    public void multiupload(HttpServletRequest request, String path1,
//                            String path2, HttpServletResponse actioncontext,String t) throws IOException {
//        logger.info("添加文件");
//        String re=null;
//        String sub=null;
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//        MultipartFile imgFile1 = multipartRequest.getFile("file");// 获取上次文件名
//        logger.info("----->" + imgFile1.getOriginalFilename());
//        List<String> fileTypes = new ArrayList<String>();
//        fileTypes.add("jpg");
//        fileTypes.add("jpeg");
//        fileTypes.add("bmp");
//        fileTypes.add("gif");
//        fileTypes.add("png");
//        fileTypes.add("doc");
//        fileTypes.add("docx");
//        fileTypes.add("xls");
//        fileTypes.add("xlsx");
//        fileTypes.add("avi");
//        fileTypes.add("mp3");
//        fileTypes.add("mp4");
//        fileTypes.add("RAM");
//        fileTypes.add("FLV");
//        if (!(imgFile1.getOriginalFilename() == null || "".equals(imgFile1.getOriginalFilename()))) {
//            String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/image/");
//            logger.info("--->" + path1 + "--->" + path2);
//            logger.info("上传路径---->" + uploadfile);
//            String fileExt = imgFile1.getOriginalFilename().substring(imgFile1.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
//            if (fileTypes.contains(fileExt)) {
//                File file1 = this.getFile(imgFile1, uploadfile, fileTypes);
//                Attachment attachment = new Attachment();
//                attachment.setAttachment(file1.getName());
//                attachment.setAttachmentpath(uploadfile);
//                attachment.setAddtime(new Date());
//                attachment.setTimstamp(t);
//                attachmentService.save(attachment);
//                logger.info("完成上传------>" + file1);
//                logger.info(file1.toString());
//                re=file1.toString();
//                sub=re.substring(re.lastIndexOf(System.getProperty("file.separator"))+1);
//                logger.info(sub);
//                actioncontext.setContentType("text/html");
//                PrintWriter out;
//                out = actioncontext.getWriter();
//                out.println(sub);
//            }else{
//                actioncontext.setContentType("text/html");
//                PrintWriter out;
//                out = actioncontext.getWriter();
//                out.println("此类型的文件不允许上传,上传失败！");
//            }
//        }
//    }
//
//    /**
//     * 上传apk
//     * @param request
//     * @param path1
//     * @param path2
//     * @param actioncontext
//     * @param version
//     * @throws java.io.IOException
//     */
//    @RequestMapping(value="apkd")
//    public void apkdupload(HttpServletRequest request, String path1,
//                            String path2, HttpServletResponse actioncontext,
//                            String version) throws IOException {
//        logger.info("添加文件");
//        String re=null;
//        String sub=null;
//        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
//        MultipartFile imgFile1 = multipartRequest.getFile("file");// 获取上次文件名
//        logger.info("----->" + imgFile1.getOriginalFilename());
//        List<String> fileTypes = new ArrayList<String>();
//        fileTypes.add("apk");
//        if (!(imgFile1.getOriginalFilename() == null || "".equals(imgFile1.getOriginalFilename()))) {
//            String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/apk");
//            logger.info("--->" + path1 + "--->" + path2);
//            logger.info("上传路径---->" + uploadfile);
//            String fileExt = imgFile1.getOriginalFilename().substring(imgFile1.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
//            if (fileTypes.contains(fileExt)) {
//                File file1 = this.getFile(imgFile1, uploadfile, fileTypes);
//                Attachment attachment = new Attachment();
//                attachment.setAttachment(file1.getName());
//                attachment.setAttachmentpath(version);
//                attachment.setAddtime(new Date());
//                attachment.setTimstamp("apk");
//                attachmentService.save(attachment);
//                logger.info("完成上传------>" + file1);
//                logger.info(file1.toString());
//                re=file1.toString();
//                sub=re.substring(re.lastIndexOf("/")+1);
//                logger.info(sub);
//                actioncontext.setContentType("text/html");
//                PrintWriter out;
//                out = actioncontext.getWriter();
//                out.println(sub);
//            }else{
//                actioncontext.setContentType("text/html");
//                PrintWriter out;
//                out = actioncontext.getWriter();
//                out.println("此类型的文件不允许上传,上传失败！");
//            }
//        }
//    }
//
//
//
//	/**
//	 * 图片删除（数据库中删除以及真实文件也删除掉）
//	 * @param imageName
//	 * @param actioncontext
//	 * @throws java.io.IOException
//	 */
//	@RequestMapping(value = "remove")
//	public void remove(String imageName,HttpServletResponse actioncontext) throws IOException{
//		String sql = "delete from t_attachment where attachment='"+imageName.replaceAll("\r|\n", "")+"'";
//		attachmentService.executeSql(sql);
//		String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/image/");
//		FileUtils.deleteFile(uploadfile + System.getProperty("file.separator") + imageName.replaceAll("\r|\n", ""));
//		actioncontext.setContentType("text/html");
//		PrintWriter out;
//		out = actioncontext.getWriter();
//		out.println("删除完成");
//	}
//
//	/**
//	 * 设置封面后修改addtime，为了倒序排列文件
//	 * @param imageName
//	 * @param actioncontext
//	 * @throws java.io.IOException
//	 */
//	@RequestMapping(value = "setfm")
//	public void setfm(String imageName,String imageName1,HttpServletResponse actioncontext) throws IOException{
//		Map<String,Object> param = new HashMap<String,Object>();
//		Map<String,Object> param1 = new HashMap<String,Object>();
//		param.put("imageName", imageName.replaceAll("\r|\n", ""));
//		List<Attachment> ats = attachmentService.findHql("from Attachment where attachment=:imageName", param);
//		param1.put("imageName1", imageName1.replaceAll("\r|\n", ""));
//		List<Attachment> ats1 = attachmentService.findHql("from Attachment where attachment=:imageName1", param1);
//		String hql = "update Attachment set addtime='"+ats1.get(0).getAddtime()+"' where attachment='"+imageName.replaceAll("\r|\n", "")+"'";
//		attachmentService.executeHql(hql);
//		String hql1 = "update Attachment set addtime='"+ats.get(0).getAddtime()+"' where attachment='"+imageName1.replaceAll("\r|\n", "")+"'";
//		attachmentService.executeHql(hql1);
//		actioncontext.setContentType("text/html");
//		PrintWriter out;
//		out = actioncontext.getWriter();
//		out.println("设置封面完成");
//	}
//
//	@RequestMapping(value = "yp")
//	public void addYp(HttpServletRequest request, String path1,
//			String path2, HttpServletResponse actioncontext) throws IOException {
//		 String filename = request.getParameter("filename");
//		 String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/media/");
//		 BufferedWriter bWriter=new BufferedWriter(new FileWriter(uploadfile+"/"+filename+".wav"));
//		 bWriter.write(100000000);
//		 bWriter.close();
//		 String is = request.getParameter("data");
//		 //BufferedReader bReader=new BufferedReader(request.getRealPath(filename+".wav"));
//
//		 /*System.out.println(bReader.read());
//		 System.out.println(bReader.read());*/
//		 //bReader.read();
//		FileOutputStream fos = new FileOutputStream(uploadfile+"/"+filename+".wav");
//		 //创建输入流读取指定文件
//	       java.io.FileInputStream fis = new java.io.FileInputStream(new File(uploadfile+"/"+filename+".wav"));
//	         byte[] buffer = new byte[1024];
//	         int len = 0;
//	         while ((len = fis.read(buffer)) > 0) //循环读取文件到输出流
//	         {
//	            fos.write(buffer , 0 , len);   //使用输出流输出文件。
//	         }
//
//	         fis.close();
//	         fos.close();
//	}
//
//	private File getFile2(MultipartFile imgFile, String brandName, List fileTypes) {
//		String fileName = imgFile.getOriginalFilename();
//		// 获取上传文件类型的扩展名,先得到.的位置，再截取从.的下一个位置到文件的最后，最后得到扩展名
//		String ext = fileName.substring(fileName.lastIndexOf(".") + 1,
//				fileName.length());
//		logger.info("获取扩展名---->" + ext);
//		// 对扩展名进行小写转换
//		ext = ext.toLowerCase();
//
//		File file = null;
//		if (fileTypes.contains(ext)) { // 如果扩展名属于允许上传的类型，则创建文件
//			// file = this.creatFolder(typeName, brandName, fileName);
//			UUID uuid  =  UUID.randomUUID();
//			file = this.creatFolder2(brandName, UUID.randomUUID().toString() + fileName);
//			logger.info("完整路径--->" + file);
//			try {
//				imgFile.transferTo(file); // 保存上传的文件
//			} catch (IllegalStateException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		}
//		return file;
//	}
//
//	private File getFile(MultipartFile imgFile, String brandName, List fileTypes) {
//		String fileName = imgFile.getOriginalFilename();
//		// 获取上传文件类型的扩展名,先得到.的位置，再截取从.的下一个位置到文件的最后，最后得到扩展名
//		String ext = fileName.substring(fileName.lastIndexOf(".") + 1,
//				fileName.length());
//		logger.info("获取扩展名---->" + ext);
//		// 对扩展名进行小写转换
//		ext = ext.toLowerCase();
//
//		File file = null;
//		if (fileTypes.contains(ext)) { // 如果扩展名属于允许上传的类型，则创建文件
//			// file = this.creatFolder(typeName, brandName, fileName);
//			UUID uuid  =  UUID.randomUUID();
//			file = this.creatFolder(brandName, UUID.randomUUID().toString() + fileName.toLowerCase());
//			logger.info("完整路径--->" + file);
//			try {
//				imgFile.transferTo(file); // 保存上传的文件
//			} catch (IllegalStateException e) {
//				e.printStackTrace();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		}
//		return file;
//	}
//
//	// private File creatFolder(String typeName, String brandName, String
//	// fileName) {
//	private File creatFolder(String brandName, String fileName) {
//		File file = null;
//		// typeName = typeName.replaceAll("/", ""); // 去掉"/"
//		// typeName = typeName.replaceAll(" ", ""); // 替换半角空格
//		// typeName = typeName.replaceAll(" ", ""); // 替换全角空格
//
//		// brandName = brandName.replaceAll("/", ""); // 去掉"/"
//		// brandName = brandName.replaceAll(" ", ""); // 替换半角空格
//		// brandName = brandName.replaceAll(" ", ""); // 替换全角空格
//
//		// File firstFolder = new File("c:/" + typeName); // 一级文件夹
//		File firstFolder = new File(brandName);
//		logger.info("文件路径--->" + firstFolder);
//		String suffix = fileName.substring(fileName.lastIndexOf('.'));
//		logger.info("截取文件后缀--->" + suffix);
//		String prefix = System.currentTimeMillis() + "";
//		String newfileName = prefix + suffix;
//		if (firstFolder.exists()) { // 如果一级文件夹存在，则检测二级文件夹
//		// File secondFolder = new File(firstFolder, brandName);
//		// if (secondFolder.exists()) { // 如果二级文件夹也存在，则创建文件
//		// file = new File(secondFolder, fileName);
//		// } else { // 如果二级文件夹不存在，则创建二级文件夹
//		// secondFolder.mkdir();
//		// file = new File(secondFolder, fileName); // 创建完二级文件夹后，再合建文件
//			// file = new File(fileName);
//			logger.info("现在路径---->" + brandName);
//			file = new File(brandName + "/" + newfileName);
//			// }
//		} else { // 如果一级不存在，则创建一级文件夹
//			firstFolder.mkdir();
//			// File secondFolder = new File(brandName);
//			// if (secondFolder.exists()) { // 如果二级文件夹也存在，则创建文件
//			// file = new File(secondFolder, fileName);
//			// } else { // 如果二级文件夹不存在，则创建二级文件夹
//			// secondFolder.mkdir();
//			// file = new File(secondFolder, fileName);
//			logger.info("现在路径---->" + brandName);
//			file = new File(brandName + "/" + newfileName);
//			// }
//		}
//		return file;
//	}
//
//
//	private File creatFolder2(String brandName, String fileName) {
//		File file = null;
//		// typeName = typeName.replaceAll("/", ""); // 去掉"/"
//		// typeName = typeName.replaceAll(" ", ""); // 替换半角空格
//		// typeName = typeName.replaceAll(" ", ""); // 替换全角空格
//
//		// brandName = brandName.replaceAll("/", ""); // 去掉"/"
//		// brandName = brandName.replaceAll(" ", ""); // 替换半角空格
//		// brandName = brandName.replaceAll(" ", ""); // 替换全角空格
//
//		// File firstFolder = new File("c:/" + typeName); // 一级文件夹
////		File firstFolder = new File(brandName);
////		logger.info("文件路径--->" + firstFolder);
////		String suffix = fileName.substring(fileName.lastIndexOf('.'));
////		logger.info("截取文件后缀--->" + suffix);
////		String prefix = System.currentTimeMillis() + "";
////		String newfileName = prefix + suffix;
////		if (firstFolder.exists()) { // 如果一级文件夹存在，则检测二级文件夹
////			 File secondFolder = new File(firstFolder, brandName);
////			 if (secondFolder.exists()) { // 如果二级文件夹也存在，则创建文件
////			 	file = new File(secondFolder, fileName);
////			 } else { // 如果二级文件夹不存在，则创建二级文件夹
////				 secondFolder.mkdir();
////				 file = new File(secondFolder, fileName); // 创建完二级文件夹后，再合建文件
////				 file = new File(fileName);
////				logger.info("现在路径---->" + brandName);
////				file = new File(brandName + "/" + newfileName);
////			 }
////		} else { // 如果一级不存在，则创建一级文件夹
////			firstFolder.mkdir();
////			// File secondFolder = new File(brandName);
////			// if (secondFolder.exists()) { // 如果二级文件夹也存在，则创建文件
////			// file = new File(secondFolder, fileName);
////			// } else { // 如果二级文件夹不存在，则创建二级文件夹
////			// secondFolder.mkdir();
////			// file = new File(secondFolder, fileName);
////			logger.info("现在路径---->" + brandName);
////			file = new File(brandName + "/" + newfileName);
////			// }
////		}
////		return file;
////	}
////
////
////	@RequestMapping(value="tmscan_upload")
////	public void tmscan_upload(HttpServletRequest request,
////							HttpServletResponse actioncontext,
////							String t,String form_id,String case_id) throws IOException {
////		logger.info("添加文件");
////		String re=null;
////		String sub=null;
////		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
////		MultipartFile imgFile1 = multipartRequest.getFile("file");// 获取上次文件名
////		logger.info("----->" + imgFile1.getOriginalFilename());
////		List<String> fileTypes = new ArrayList<String>();
////		fileTypes.add("doc");
////		fileTypes.add("DOC");
////		fileTypes.add("docx");
////		fileTypes.add("DOCX");
////		fileTypes.add("xls");
////		fileTypes.add("xlsx");
////		fileTypes.add("XLS");
////		fileTypes.add("XLSX");
////		if (!(imgFile1.getOriginalFilename() == null || "".equals(imgFile1.getOriginalFilename()))) {
////			String uploadfile = ContextHolderUtils.getServletContext().getRealPath("/attached/tm/tzupload/");
////			logger.info("上传路径---->" + uploadfile);
////			String fileExt = imgFile1.getOriginalFilename().substring(imgFile1.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
////			if (fileTypes.contains(fileExt)) {
////				File file1 = this.getFile(imgFile1, uploadfile, fileTypes);
////				logger.info("完成上传------>" + file1);
////				logger.info(file1.toString());
////				re=file1.toString();
////				sub=re.substring(re.lastIndexOf(System.getProperty("file.separator"))+1);
////				logger.info(sub);
////				actioncontext.setContentType("text/html");
////				PrintWriter out;
////				out = actioncontext.getWriter();
////				out.println(sub.replace("\n",""));
////
////				String wsmenu_update_sql = "update tm_file_download set filedownload='"+sub+"' where id='"+form_id+"' ";
////				attachmentService.updateBySqlString(wsmenu_update_sql);
////
////			}else{
////				actioncontext.setContentType("text/html");
////				PrintWriter out;
////				out = actioncontext.getWriter();
////				out.println("此类型的文件不允许上传,上传失败！");
////			}
////		}
////	}
//
//}